
const APP = {
    swithcConfig: [
        { depth: 10, id: 'du6', desc: '首页' },
        { depth: 10, id: 'dua', desc: '热门' },
        { depth: 10, id: 'du9', desc: '发布' },
        { depth: 10, id: 'du8', desc: '消息' },
        { depth: 10, id: 'du7', desc: '我' },
    ],
    //检查存储权限
    hasStoragePermission: function () {
        // 获取应用的PackageManager实例
        var pm = context.getPackageManager();
        // 获取应用的包名
        var packageName = context.getPackageName();
        // 检查权限
        var permission = android.Manifest.permission.WRITE_EXTERNAL_STORAGE;
        var result = pm.checkPermission(permission, packageName);

        // 如果结果等于PackageManager.PERMISSION_GRANTED，则表示有权限
        return result == android.content.pm.PackageManager.PERMISSION_GRANTED;
    },
    //打开应用
    launchApp: function (packageName) {
        // 通过包名打开应用
        var appInfo = context.getPackageManager().getLaunchIntentForPackage(packageName);
        if (appInfo != null) {
            context.startActivity(appInfo);
            return true;
        } else {
            toast("找不到应用: " + packageName);
            return true;
        }
    },
    //按坐标点击
    click: function (x, y, delay, optip) {
        click(x, y);
        console.log(optip);
        sleep(delay * 1000);
    },
    HttpRequest: function () {
        var url = 'https://zfg.isimi.net/app/code/getCodeData';
        var param = {
            a: 1,
            b: 2,
        };

        let response = http.postJson(url, param);
        if (response.statusCode == 200) {
            let jsonData = response.body.json();
            return jsonData;
        } else {
            console.log('请求失败，状态码', response.statusCode);
            return false;
        }
    },
    getTask: function () {
        var jsonData = { type: 'send_post' };

        return jsonData;
    },
     randomSleep(min,max){
       let time = max ? (Math.floor(Math.random() * (max - min + 1)) + min)*1000 : (Math.floor(Math.random() * (4)) + 3) * 1000
       console.log('睡：' + time + 'ms');
       sleep(time)
    },
    getDate(){
        function formatDatetimeVal(str){
            var num;
            str>9?num=str:num="0"+str;
            
            return num;
        };
		var date = new Date();
		var year=date.getFullYear();//当前年份
		var month=date.getMonth();//当前月份
		var data=date.getDate();//天
		var hours=date.getHours();//小时
		var minute=date.getMinutes();//分
		var second=date.getSeconds();//秒
		
		var time = year+"-"+formatDatetimeVal((month+1))+"-"+formatDatetimeVal(data)+" "+formatDatetimeVal(hours)+":"+formatDatetimeVal(minute)+":"+formatDatetimeVal(second);
		return time;
	}
};
module.exports = APP